<?php
namespace app\api\exception;

use think\exception\Handle;
use think\exception\HttpException;

class Http extends Handle
{

    public function render(\Exception $e)
    {

        if(request()->module() == 'api'){
            if ($e instanceof HttpException) {
                $statusCode = $e->getStatusCode();
            }

            if (!isset($statusCode)) {
                $statusCode = 500;
            }

            $result = [
                'msg'  => $e->getMessage(),
                'time' => $_SERVER['REQUEST_TIME'],
            ];
            return response($result, $statusCode, [], 'json');
        }
        return parent::render($e);
    }

}